package com.lc.utils;
import java.lang.reflect.Proxy;

import org.springframework.beans.factory.FactoryBean;

/**
 * Created by lichao on 2017/6/1.
 */
    @SuppressWarnings("unchecked")
/**
 *
 * <p class="detail">
 * 功能：自定义bean
 * </p>
 * @ClassName: KingBeanFactory
 * @version V1.0
 * @date 2014年12月17日
 * @author <a href="mailto:wangs@financegt.com">kings</a>
 * @param <T>
 */
    public class KingBeanFactory <T> implements FactoryBean<T>{
        private Class<T>  kInterface;

        private KingProxy proxy;

        @Override
        public T getObject() throws Exception {
            return newInstance();
        }

        @Override
        public Class<?> getObjectType() {
            return kInterface;
        }

        public KingProxy getProxy() {
            return proxy;
        }


        @Override
        public boolean isSingleton() {
            return true;
        }

        private T newInstance() {
            return (T) Proxy.newProxyInstance(kInterface.getClassLoader(),
                    new Class[] {kInterface }, proxy);
        }

        public void setProxy(KingProxy proxy) {
            this.proxy = proxy;
        }

        public Class<T> getkInterface() {
            return kInterface;
        }

        public void setkInterface(Class<T> kInterface) {
            this.kInterface = kInterface;
        }


    }
